package com.huitone.smspfm.socket.core;

import org.apache.commons.codec.binary.Base64;

import com.bin.common.utils.StringUtils;
import com.huitone.smspfm.socket.model.AccountInfo;

/**   
* @Title SimpleUserChecker.java 
* @Package com.huitone.smspfm.socket.core 
* @Description TODO(用一句话描述该文件做什么) 
* @author ybliang   
* @date 2017年5月11日 下午2:26:02 
* @version V1.0   
*/
public class ClientServerUserChecker extends AbstractUserChecker {
	
	private String username = null;
	private String password = null;
	
	public ClientServerUserChecker(String username, String password) {
		this.username = username;
		this.password = StringUtils.trim(Base64.encodeBase64String(StringUtils.toString(password).getBytes()));
	}

	@Override
	public boolean isUserLogin(String username, String password) {
		
		return isUserLogin(null, username, password);
	}

	@Override
	public boolean isUserLogin(String srvNode, String username, String password) {
		
		boolean result = false;
		
		if (StringUtils.equals(this.username, username) && StringUtils.equals(this.password, password)) {
			result = true;
		}
		
		return result;
	}
	
	@Override
	public AccountInfo isUserLogin2(String username, String password) {
		
		AccountInfo accountInfo = null;
		
		if (StringUtils.equals(this.username, username) 
				&& StringUtils.equals(this.password, password)) {
			accountInfo = new AccountInfo();
			accountInfo.setLoginName(username);
			accountInfo.setLoginPassword(password);
			accountInfo.setMaxFlux(null);
			accountInfo.setLogin(true);
		}
		
		return accountInfo;
	}
	
	@Override
	public AccountInfo isUserLogin2(String srvNode, String username, String password) {
		
		AccountInfo accountInfo = null;
		
		if (StringUtils.equals(this.username, username) 
				&& StringUtils.equals(this.password, password)) {
			accountInfo = new AccountInfo();
			accountInfo.setSrvNode(srvNode);
			accountInfo.setLoginName(username);
			accountInfo.setLoginPassword(password);
			accountInfo.setMaxFlux(null);
			accountInfo.setLogin(true);
		}
		
		return accountInfo;
	}

}
